﻿using Spine.Unity;

namespace Core.Animation {
    public class SpineAnimation : IAnimation {
        private SkeletonAnimation mAnim;
        public SpineAnimation(SkeletonAnimation anim) {
            mAnim = anim;
        }
        
        public void Play(string animName,bool isLoop) {
            mAnim.AnimationState.SetAnimation(0, animName,isLoop);
            mAnim.Update(0);
            mAnim.AnimationState.Data.DefaultMix = .0f;
        }

        public void Stop(string animName) {
            mAnim.AnimationState.ClearTrack(0);
        }

        public bool HasClip(string animName) {
            return mAnim.AnimationState.Data.SkeletonData.FindAnimation(animName) != null;
        }

        public float GetDuration(string animName) {
            return mAnim.AnimationState.GetCurrent(0).Animation.Duration;
        }
    }
}